<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <input type="text" v-model="msg">
    <hr>
    监听对象
    <input type="text" v-model="obj.a">
    <hr>
    <input type="text" v-model="obj.b">
  </div> 
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data: {
        msg: '',
        obj: {
          a: 10,
          b: 20
        }
      },
      watch: {
        msg(newVal,oldVal){
          console.log("msg改变了新值是" + newVal)
        },
       /*  obj (newVal) {
          console.log("obj变化了")
        } */
        'obj.a' (newVal) {
          console.log('obj的a属性变化了')
        },
        // 深度监听对象
        obj: {
          handler (newVal) { // 监听器函数
            console.log(newVal)
          },
          deep: true // 深度监听
        }
      }
    })
  </script>
</body>
</html>